package com.edushare.common.vo;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.edushare.common.util.CryptionUtil;
import com.edushare.common.vo.auto._TempUsers;

public class TempUsers extends _TempUsers implements Notifiable{

	private static final long serialVersionUID = 1315665211352533215L;
	private static Log log = LogFactory.getLog(TempUsers.class);
	
	public static final int STATUS_NOT_VERIFIED = 0;
	public static final int STATUS_VERIFIED = 1;
	
	public String getMarkupId() {
		// TODO Auto-generated method stub
		return null;
	}

	public String getMarkupName() {
		// TODO Auto-generated method stub
		return null;
	}

	public String getMarkupText() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setPassword(String plainTxtPwd){
		String encryptPwd = null;
		encryptPwd = DigestUtils.sha256Hex(plainTxtPwd);
		super.setPassword(encryptPwd);
	}
	
	@Override
	public void setConfKey(String uniqueKey){
		String timeStampedKey = uniqueKey + "." + System.currentTimeMillis();
		super.setConfKey(timeStampedKey);
	}
	
	/**
	 * Returns key after encrypting the plain-text key
	 */
	@Override
	public String getConfKey(){
		String cKey = null;
		try {
			cKey = CryptionUtil.encrypt(super.getConfKey());
		} catch (InvalidKeyException e) {
			log.error("Error encrypting confidential key",e);
			e.printStackTrace();
		} catch (IllegalBlockSizeException e) {
			log.error("Error encrypting confidential key",e);
			e.printStackTrace();
		} catch (BadPaddingException e) {
			log.error("Error encrypting confidential key",e);
			e.printStackTrace();
		} catch (NoSuchAlgorithmException e) {
			log.error("Error encrypting confidential key",e);
			e.printStackTrace();
		} catch (NoSuchPaddingException e) {
			log.error("Error encrypting confidential key",e);
			e.printStackTrace();
		}
		return cKey;
	}

}
